package com.mega.server;

import java.util.Properties;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.impl.ActiveMQUuidGenerator;
import org.apache.camel.main.Main;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.mega.ebcs.integration.pool.TimerPoolDataQueueBean;
import com.mega.ebcs.integration.route.ClientToHostRoute;
import com.mega.ebcs.integration.route.FileToClientRoute;
import com.mega.ebcs.integration.route.ResponseHostToFileRoute;



public class IntegrationServer {
	public static void main(String args[]) throws Exception {
		new IntegrationServer().boot();		
	}
	
	public void boot() throws Exception {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("camel-context.xml");
		Properties prop = (Properties)ctx.getBean("props");
		CamelContext context = (CamelContext) ctx.getBean("context");
		context.setUuidGenerator(new ActiveMQUuidGenerator("EBCS"));
		
		ConsumerTemplate ct = context.createConsumerTemplate();
		ProducerTemplate pt = context.createProducerTemplate();
		
		final TimerPoolDataQueueBean cool = new TimerPoolDataQueueBean();
		
		cool.setProducer(pt);
		cool.setConsumer(ct);
		cool.setProp(prop);		
		
		context.addRoutes(new ClientToHostRoute(prop));
		context.addRoutes(new ResponseHostToFileRoute(cool, prop));
		context.addRoutes(new FileToClientRoute());
		
		Main main = new Main();
		main.run();
	}
}
